package com.woniu.park.service.impl;

import com.woniu.park.exception.BannerException;
import com.woniu.park.dao.BannerMapper;
import com.woniu.park.pojo.Banner;
import com.woniu.park.pojo.BannerExample;
import com.woniu.park.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 张洛诚
 * @date 2019/8/29 20:11:46
 * @description
 */
@Service
public class BannnerServiceImpl implements BannerService {
    @Autowired
    BannerMapper bannerMapper;
    @Override
    @Cacheable(value = "Banners",key = "#typeId")
    public List<Banner> getBannersByTypeId(Integer typeId) {
        if(typeId<1||typeId>5){
            throw new BannerException("ID参数传入错误");
        }
        BannerExample bannerExample=new BannerExample();
        bannerExample.createCriteria().andTypeIdEqualTo(typeId);
        List<Banner> banners = bannerMapper.selectByExample(bannerExample);
        return banners;
    }
}
